package com.example.myapplication2.ContentProvider;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.util.Log;

import java.util.Date;

public class BookContentProvider extends ContentProvider {
    public BookContentProvider() {
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        return 128;
    }

    @Override
    public String getType(Uri uri) {
        return "你猜呀.";
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        Log.d("info", "BookContentProvider的插入成功消息");
        String name = (String) values.get("name");
        Log.d("info", name);
        //向外发布通知
        Uri uri1 = ContentUris.withAppendedId(uri, new Date().getTime());
        getContext().getContentResolver().notifyChange(uri1,null);
        return uri;
    }

    @Override
    public boolean onCreate() {

        Log.d("info", "BookContentProvider的创建成功消息");
        //返回一个true,提示上层,创建成功
        return true;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
                        String[] selectionArgs, String sortOrder) {

        return null;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection,
                      String[] selectionArgs) {
        return 128;
    }
}